﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace LemonAlgorithm.SkylineAlgorithm
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Debug.WriteLine("---------------开始------------hello");
            // 创建带约束的打包器
            var packer = new ConstrainedSkylinePacker(containerWidth: 10f, containerHeight: 8f, wallClearance: 0.1f);

            // 添加禁止区域（门区域和窗户区域）- 使用四个参数的构造函数
            packer.AddForbiddenArea(new SkylinePacker.Rectangle(0f, 1.5f, 1f, 2f, "Door"));
            packer.AddForbiddenArea(new SkylinePacker.Rectangle(8f, 0f, 0.5f, 1f, "Window"));

            // 创建柜子 - 使用两个参数的构造函数
            var cabinets = new List<SkylinePacker.Rectangle>
        {
            new SkylinePacker.Rectangle(2f, 1f, "Cabinet1"),
            new SkylinePacker.Rectangle(1.5f, 0.8f, "Cabinet2"),
            new SkylinePacker.Rectangle(3f, 1.2f, "Cabinet3"),
            new SkylinePacker.Rectangle(1f, 1f, "Cabinet4"),
            new SkylinePacker.Rectangle(2.5f, 0.9f, "Cabinet5")
        };

            // 执行打包
            var placedCabinets = packer.Pack(cabinets, PackingStrategy.HeightDecreasing);

            // 输出结果
            Debug.WriteLine("Constrained Packing Results:");
            foreach (var cabinet in placedCabinets)
            {
                Debug.WriteLine($"{cabinet.Id}: Position({cabinet.X:F2}, {cabinet.Y:F2}), " +
                                $"Size({cabinet.Width:F2}x{cabinet.Height:F2})");
            }

            Debug.WriteLine($"Successfully placed {placedCabinets.Count} out of {cabinets.Count} cabinets");

            // 计算效率
            float totalArea = placedCabinets.Sum(c => c.Area);
            float containerArea = 10f * 8f;
            float efficiency = totalArea / containerArea;
            Debug.WriteLine($"Packing efficiency: {efficiency:P2}");


            Debug.WriteLine("---------------结束------------hello");
        }
    }
}
